{load href="/static/js/laydate/laydate.js" /}
<div class="row">
<div class="col-xs-12 col-md-5 col-md-offset-6">        
    <form class="form-horizontal"  action="{:url('');}"  method="post">
        <div class="form-group">
            <label for="input_plan_str" class="col-sm-3 control-label">目标名称</label>
            <div class="col-sm-9">
                <input name="plan_str" type="text" class="form-control" id="input_plan_str" placeholder="手机/邮箱">
            </div>
        </div>
        <div class="form-group">
            <label for="p_datetime_id" class="col-sm-3 control-label">计划完成日期</label>
            <div class="col-sm-9">
                <input id="p_datetime_id" name="p_datetime" type="text" class="form-control layui-input"  placeholder="yyyy年MM月dd日" lay-key="12">
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-offset-7 col-sm-5">
                <button id="submit" type="submit" class="btn btn-default">添加</button>
            </div>
        </div>
    </form>
</div>
</div>
<script>
    $ (function ()
    {
        laydate.render({
            elem: '#p_datetime_id'
            ,format: 'yyyy年MM月dd日'
        });
        
        $("#captcha").on('click',function()
        {
           let img_src = $(this).attr('src')+"?seed="+Math.random; 
           $(this).attr('src',img_src);
        });
        
        function error_layer (msg)
        {
            layer.open ({
                title: '错误提示',
                icon: 2,
                content: msg,
                yes: function ()
                {
                    layer.closeAll ();
                }
            });
        }

        function success_layer (msg)
        {
            layer.open ({
                title: '成功提示',
                icon: 1,
                content: msg,
                yes: function ()
                {
                    layer.closeAll ();
                    location.href = "{:merge_url('plan/plan_list')}";
                }
            });
        }

        $ ("#submit").on ('click', function (eve)
        {
            eve.preventDefault ();
            let url = $ ('form').attr ('action');
            let data = $('form').serialize();
            $.post (url, data, function (res)
            {
                if (res.code)
                {
                    success_layer(res.msg);
                }
                else
                {
                    error_layer(res.msg);
                }
            });
        });
    });

</script>